<?php
class mapdatacollection extends daocollection implements daocollectioninterface
{
	public function __construct(dao $currentitem)
	{
		$this->currentitem = $currentitem;
	}
	
	public function getwithdata()
	{
		$connection = db::factory('mysql');
		
		if(is_null($this->currentitem->type)){
			$sql = "SELECT id,what,AsText(mapdata) as mapdata
					FROM Items WHERE !ISNULL(mapdata)
					ORDER BY id DESC";
		}else{
			$sql = "SELECT id,what,AsText(mapdata) as mapdata
					FROM Items WHERE !ISNULL(mapdata)
					AND type={$this->currentitem->type}
					ORDER BY id DESC";
		}
		$results = $connection->getArray($sql);
		
		$this->populate($results, 'item');
	}
}